package com.kwt.learn.string;

/**
 * inter方法，使得引用指向常量池中对象
 */
public class String01 {
    public static void main(String[] args) {

        String str1 = "nihao";
        String str2 = new String("nihao");
        System.out.println(hashcode(str1));//输出 1627800613
        System.out.println(hashcode(str1.intern())); //输出 1627800613
        System.out.println("--------------------------------------");
        System.out.println(hashcode(str2));//输出 2065530879
        System.out.println(hashcode(str2.intern())); //输出 1627800613
        System.out.println(hashcode(str2));//输出 2065530879
    }

    /**
     * 返回Object类的hashCode方法
     */
    public static int hashcode(String str) {
        return System.identityHashCode(str);
    }
}
